---
title: "Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
---
```{r setup, include=FALSE}
# rmarkdown::render("dashboard.Rmd", output_format = "flexdashboard::flex_dashboard")
library(flexdashboard)
library(tidyverse)
library(p8105.datasets)
library(plotly)
library(patchwork)
theme_set(theme_minimal() + theme(legend.position = 'bottom'))
options(
ggplot2.continuous.colour = 'viridis',
ggplot2.continuous.fill = 'viridis'
)
scale_colour_discrete = scale_colour_viridis_d
scale_fill_discrete = scale_fill_viridis_d
# Set a seed
set.seed(777)
```
```{r Prepare data, echo = FALSE, warning = FALSE, message = FALSE}
data(ny_noaa)
# data(nyc_airbnb)
year_filter = '2017'
ny_noaa =
ny_noaa %>%
janitor::clean_names() %>%
# Pick 4 stations with few missing values
filter(
id %in% c('USC00300055', 'USC00301401', 'USC00303025')
) %>%
drop_na() %>%
mutate(tmax = as.double(tmax)/10,
tmin = as.double(tmin)/10) %>%
rename(station_id = id)
# ny_noaa
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r Scores by month and cuisine_description, echo = FALSE, warning = FALSE, message = FALSE}
mean_tmin_df =
ny_noaa %>%
mutate(year = lubridate::year(date)) %>%
group_by(year, station_id) %>%
summarise(mean_tmin = mean(tmin))
# plot_ly(
# x = ~year, y = ~mean_tmin, type = "scatter", mode = "markers",
# color = ~station_id) +
# theme(axis.text.x = element_text(angle = 90, hjust = 1))
Boxplot =
ggplot(mean_tmin_df, aes(x = year, y = mean_tmin, color = station_id)) +
geom_line()
ggplotly(Boxplot)
```
Column {data-width=350}
-----------------------------------------------------------------------
### Chart B
```{r, echo = FALSE, warning = FALSE, message = FALSE}
ny_noaa %>%
mutate(month = lubridate::month(date),
year = lubridate::year(date),
season = case_when(
month > 2 & month <= 5 ~ 'Spring',
month > 5 & month <= 8 ~ 'Summer',
month > 8 & month <= 11 ~ 'Autumn',
TRUE ~ 'Winter'
),
season = fct_reorder(season, month, max),
temperature_diff = tmax - tmin) %>%
filter(year >= 2000) %>%
plot_ly(y = ~temperature_diff, color = ~season, type = "box", colors = "viridis")
```
### Chart C
```{r, echo = FALSE, warning = FALSE, message = FALSE}
ny_noaa %>%
mutate(month = lubridate::month(date),
year = lubridate::year(date)) %>%
filter(year >= 2000) %>%
group_by(month) %>%
summarise(mean_prcp = mean(prcp),
mean_tmin = mean(tmin)) %>%
plot_ly(x = ~month, y = ~mean_prcp, color = ~mean_tmin, type = "bar", colors = "Blues")
```